<template>
  <div class="app-container">
    <el-button-group style="display: inline-block">
      <el-button type="primary" :plain="plainA" @click="plainDataA"
        >设计清单</el-button
      >
      <el-button type="primary" :plain="plainB" @click="plainDataB"
        >施工清单</el-button
      >
      <el-button type="primary" :plain="plainC" @click="plainDataC"
        >养护清单</el-button
      >
      <el-button type="primary" :plain="plainD" @click="plainDataD"
        >管理清单</el-button
      >
    </el-button-group>
    <div style="display: inline-block; margin-bottom: 18px; margin-left: 590px">
      <el-select
        class="custom-select"
        :disabled="idsdisabled"
        v-model="valueBatch"
        placeholder="批量设置"
        @change="openBatchOpen"
      >
        <el-option
          v-for="item in optionsBatch"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        >
        </el-option>
      </el-select>
      <el-select
        class="custom-select"
        :disabled="idsdisabled"
        v-model="valueBatchData"
        placeholder="待办任务"
        @change="openBatchOpenDate"
      >
        <el-option
          v-for="item in optionsBatchData"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        >
        </el-option>
      </el-select>
      <el-select
        class="custom-select"
        :disabled="idsdisabledOver"
        v-model="valueBatchDataOver"
        placeholder="全部待办任务"
        @change="openBatchOpenDateOver"
      >
        <el-option
          v-for="item in optionsBatchDataOver"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        >
        </el-option>
      </el-select>
    </div>
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <!-- <el-form-item prop="projectId">
        <el-input
          v-model="queryParams.projectId"
          placeholder="全部分类"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item prop="riskLevel">
        <el-select
          v-model="queryParams.riskLevel"
          placeholder="全部风险等级"
          clearable
          @keyup.enter.native="handleQuery"
        >
          <el-option
            v-for="item in dict.type.list_risk_level"
            :key="item.dictLabel"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item prop="dangerLevel">
        <el-select
          v-model="queryParams.dangerLevel"
          placeholder="全部隐患等级"
          clearable
          @keyup.enter.native="handleQuery"
        >
          <el-option
            v-for="item in dict.type.list_danger_level"
            :key="item.dictLabel"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select> </el-form-item
      ><el-form-item prop="userId">
        <el-select
          v-model="queryParams.userId"
          placeholder="全部排查责任人"
          @keyup.enter.native="handleQuery"
        >
          <el-option
            v-for="(item, index) in correctorUserIdData"
            :key="index"
            :label="item.nickName"
            :value="item.userId"
          >
          </el-option>
        </el-select> </el-form-item
      ><el-form-item prop="isTask">
        <el-input
          v-model="queryParams.isTask"
          placeholder="代办任务生成情况"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['exclude:plan:add']"
          >新建计划</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['exclude:plan:remove']"
          >删除</el-button
        >
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['exclude:plan:export']"
        >导出</el-button>
      </el-col> -->
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="planList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="45" align="center" />
      <el-table-column label="序号" align="center" prop="id" width="50" />
      <el-table-column
        label="作业工序"
        align="center"
        prop="typeName"
        width="80"
      />
      <el-table-column
        label="风险辨识(潜在事故)"
        align="center"
        prop="riskRecognize"
      />
      <el-table-column
        label="风险因素(风险描述)"
        align="center"
        prop="riskFactor"
      />
      <el-table-column
        label="风险等级"
        align="center"
        prop="riskLevel"
        width="75"
      >
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.list_risk_level"
            :value="scope.row.riskLevel"
          />
        </template>
      </el-table-column>
      <el-table-column label="管控措施" align="center" prop="controlMeasure" />
      <el-table-column
        label="日常 专项 综合"
        align="center"
        prop="excludeType"
        width="120"
      >
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.biz_exclude_type"
            :value="scope.row.excludeType"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="隐患等级"
        align="center"
        prop="dangerLevel"
        width="75"
      >
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.list_danger_level"
            :value="scope.row.dangerLevel"
          />
        </template>
      </el-table-column>
      <el-table-column label="规范依据" align="center" prop="normativeBasis" />
      <el-table-column
        label="有效时间"
        align="center"
        prop="dateRange"
        width="100"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.dateRange != null">
            <div>{{ scope.row.dateRange[0] }}</div>
            <div>至</div>
            <div>{{ scope.row.dateRange[1] }}</div>
          </span>
          <span v-else style="color: red">未设置有效时间</span>
        </template>
      </el-table-column>
      <el-table-column
        label="检查频次"
        align="center"
        prop="excludeFrequency"
        width="90"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.excludeFrequency != null">
            {{ scope.row.excludeFrequency }}次/{{ scope.row.dateType }}
            <!-- <dict-tag
              class="tagname"
              :options="dict.type.biz_date_type"
              :value="scope.row.dateType"
            /> -->
          </span>
          <span v-else style="color: red">未设置排查频次</span>
          <!-- 周期类型 -->
        </template>
      </el-table-column>
      <el-table-column
        label="允许生成任务"
        align="center"
        prop="isTask"
        width="100"
      >
        <template slot-scope="scope">
          <i class="el-icon-check" v-if="scope.row.isTask == '1'"></i>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="120"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleUpdateLook(scope.row)"
            v-hasPermi="['exclude:plan:edit']"
            >查看</el-button
          >
          <el-button
            size="mini"
            type="text"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['exclude:plan:edit']"
            >编辑</el-button
          >
          <el-button
            size="mini"
            type="text"
            @click="handleDelete(scope.row)"
            v-hasPermi="['exclude:plan:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 编辑 -->
    <el-dialog
      :title="title"
      :visible.sync="openUpdate"
      width="450px"
      :close-on-click-modal="false"
      style="margin-right: -77%"
      append-to-body
    >
      <div>注:【排查类别、时间、范围、责任人、频次、允许生成任务】</div>
      <div style="margin-top: 5px; margin-bottom: 35px">
        全部设置后可以生成任务
      </div>
      <el-form label-position="top" ref="formData" :model="form" :rules="rules">
        <el-form-item label="排查类别" prop="excludeType">
          <el-checkbox-group v-model="form.excludeType">
            <el-checkbox
              v-for="item in dict.type.biz_exclude_type"
              :key="item.value"
              :label="item.value"
            >
              {{ item.label }}
            </el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <el-form-item label="排查频次" prop="excludeFrequency">
          <el-input-number
            style="width: 120px"
            v-model="form.excludeFrequency"
            placeholder="请输入排查频次"
            :min="0"
          />次/
          <el-select
            style="width: 105px"
            v-model="form.dateType"
            placeholder="请选择时间类型(日,周,月,季度,半年)"
          >
            <el-option
              v-for="dict in SelectData"
              :key="dict.id"
              :label="dict.checkTypeName"
              :value="dict.checkTypeNo"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="责任人设置" prop="userIds">
          <el-select v-model="form.userIds" multiple placeholder="请选择责任人">
            <el-option
              v-for="(item, index) in correctorUserIdData"
              :key="index"
              :label="item.nickName"
              :value="item.userId"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="排查开始时间" prop="dateRange">
          <el-date-picker
            v-model="form.dateRange"
            type="daterange"
            range-separator="-"
            value-format="yyyy-MM-dd"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="排查范围" prop="regionIds">
          <treeselect
            :flat="true"
            :multiple="true"
            :normalizer="normalizer"
            v-model="form.regionIds"
            :options="getTreeData"
            :default-expand-level="100"
            placeholder="请选择作检查类型"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">保存</el-button>
        <el-button @click="reset">重 置</el-button>
      </div>
    </el-dialog>

    <!-- 查看 -->
    <el-dialog
      :title="title"
      :visible.sync="openUpdateLook"
      width="450px"
      :close-on-click-modal="false"
      style="margin-right: -77%"
      append-to-body
    >
      <div>注:【排查类别、时间、范围、责任人、频次、允许生成任务】</div>
      <div style="margin-top: 5px; margin-bottom: 35px">
        全部设置后可以生成任务
      </div>
      <el-form label-position="top" ref="formData" :model="form" :rules="rules">
        <el-form-item label="排查类别" prop="excludeType">
          <el-checkbox-group v-model="form.excludeType">
            <el-checkbox
              disabled
              v-for="item in dict.type.biz_exclude_type"
              :key="item.value"
              :label="item.value"
            >
              {{ item.label }}
            </el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <el-form-item label="排查频次" prop="excludeFrequency">
          <el-input-number
              disabled
            style="width: 120px"
            v-model="form.excludeFrequency"
            placeholder="请输入排查频次"
            :min="0"
          />次/
          <el-select
              disabled
            style="width: 105px"
            v-model="form.dateType"
            placeholder="请选择时间类型(日,周,月,季度,半年)"
          >
            <el-option
              v-for="dict in SelectData"
              :key="dict.id"
              :label="dict.checkTypeName"
              :value="dict.checkTypeNo"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="责任人设置" prop="userIds">
          <el-select v-model="form.userIds" multiple placeholder="请选择责任人">
            <el-option
              disabled
              v-for="(item, index) in correctorUserIdData"
              :key="index"
              :label="item.nickName"
              :value="item.userId"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="排查开始时间" prop="dateRange">
          <el-date-picker
              disabled
            v-model="form.dateRange"
            type="daterange"
            range-separator="-"
            value-format="yyyy-MM-dd"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="排查范围" prop="regionIds">
          <treeselect
              disabled
            :flat="true"
            :multiple="true"
            :normalizer="normalizer"
            v-model="form.regionIds"
            :options="getTreeData"
            :default-expand-level="100"
            placeholder="请选择作检查类型"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="openUpdateLook = false">关闭</el-button>
      </div>
    </el-dialog>

    <!-- 批量修改弹框 -->
    <el-dialog
      :title="title"
      :visible.sync="openBatch"
      width="800px"
      append-to-body
      :close-on-click-modal="false"
      :before-close="handleClose"
    >
      <el-form label-position="top" ref="form" :model="form" :rules="rules">
        <div v-if="this.valueBatch == '1'">
          <el-form-item label="排查类别" prop="excludeType">
            <el-checkbox-group v-model="form.excludeType">
              <el-checkbox
                v-for="dict in dict.type.biz_exclude_type"
                :key="dict.value"
                :label="dict.value"
              >
                {{ dict.label }}
              </el-checkbox>
            </el-checkbox-group>
          </el-form-item>
          <el-form-item label="排查频次" prop="excludeFrequency">
            <el-input-number
              style="width: 120px"
              v-model="form.excludeFrequency"
              placeholder="请输入排查频次"
              :min="0"
            />
            次/
            <el-select
              style="width: 105px"
              v-model="form.dateType"
              placeholder="请选择时间类型(日,周,月,季度,半年)"
            >
              <el-option
                v-for="dict in SelectData"
                :key="dict.id"
                :label="dict.checkTypeName"
                :value="dict.checkTypeNo"
              ></el-option>
            </el-select>
          </el-form-item>
        </div>

        <div v-if="this.valueBatch == '2'">
          <el-form-item label="排查开始时间" prop="dateRange">
            <el-date-picker
              v-model="form.dateRange"
              type="daterange"
              range-separator="-"
              value-format="yyyy-MM-dd"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            >
            </el-date-picker>
          </el-form-item>
        </div>

        <div v-if="this.valueBatch == '3'">
          <el-form-item label="排查范围" prop="regionIds">
            <treeselect
              :flat="true"
              :multiple="true"
              :normalizer="normalizer"
              v-model="form.regionIds"
              :options="getTreeData"
              :default-expand-level="100"
              placeholder="请选择作检查类型"
            />
          </el-form-item>
        </div>
        <div v-if="this.valueBatch == '4'">
          <el-form-item label="责任人设置" prop="userIds">
            <el-select
              v-model="form.userIds"
              multiple
              placeholder="请选择责任人"
            >
              <el-option
                v-for="(item, index) in correctorUserIdData"
                :key="index"
                :label="item.nickName"
                :value="item.userId"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </div>
        <div v-if="this.valueBatch == '5'">
          <el-form label-position="top" ref="form" :model="form" :rules="rules">
            <el-form-item label="排查类别" prop="excludeType">
              <el-checkbox-group v-model="form.excludeType">
                <el-checkbox
                  v-for="dict in dict.type.biz_exclude_type"
                  :key="dict.value"
                  :label="dict.value"
                >
                  {{ dict.label }}
                </el-checkbox>
              </el-checkbox-group>
            </el-form-item>
            <el-form-item label="排查频次" prop="excludeFrequency">
              <el-input-number
                style="width: 120px"
                v-model="form.excludeFrequency"
                placeholder="请输入排查频次"
                :min="0"
              />
              次/
              <el-select
                style="width: 105px"
                v-model="form.dateType"
                placeholder="请选择时间类型(日,周,月,季度,半年)"
              >
                <el-option
                  v-for="dict in SelectData"
                  :key="dict.id"
                  :label="dict.checkTypeName"
                  :value="dict.checkTypeNo"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="责任人设置" prop="userIds">
              <el-select
                v-model="form.userIds"
                multiple
                placeholder="请选择责任人"
              >
                <el-option
                  v-for="(item, index) in correctorUserIdData"
                  :key="index"
                  :label="item.nickName"
                  :value="item.userId"
                >
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="排查开始时间" prop="dateRange">
              <el-date-picker
                v-model="form.dateRange"
                type="daterange"
                range-separator="-"
                value-format="yyyy-MM-dd"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
              >
              </el-date-picker>
            </el-form-item>
            <el-form-item label="排查范围" prop="regionIds">
              <treeselect
                :flat="true"
                :multiple="true"
                :normalizer="normalizer"
                v-model="form.regionIds"
                :options="getTreeData"
                :default-expand-level="100"
                placeholder="请选择作检查类型"
              />
            </el-form-item>
          </el-form>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="batchSubmitForm">保存</el-button>
      </div>
    </el-dialog>

    <!-- 添加项目人员管理对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="1200px"
      append-to-body
      :close-on-click-modal="false"
    >
      <el-row :gutter="20">
        <el-col :span="4" :xs="24">
          <div class="head-container">
            <el-input
              v-model="deptName"
              placeholder="请输入作业工序"
              clearable
              size="small"
              prefix-icon="el-icon-search"
              style="margin-bottom: 20px"
            />
          </div>
          <div class="head-container">
            <el-tree
              :data="deptOptions"
              :props="defaultProps"
              :expand-on-click-node="false"
              :filter-node-method="filterNode"
              ref="tree"
              node-key="id"
              highlight-current
              @node-click="handleNodeClick"
            />
          </div>
        </el-col>
        <!--用户数据-->
        <el-col :span="20" :xs="24">
          <el-table
            height="600px"
            v-loading="loading"
            :data="deviseList"
            @selection-change="handleSelectionChange"
          >
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="序号" align="center" prop="id" width="55" />
            <el-table-column label="作业工序" align="center" prop="typeNo" />
            <el-table-column
              label="风险标识"
              align="center"
              prop="riskRecognize"
            />
            <el-table-column
              label="风险因素"
              align="center"
              prop="riskFactor"
            />
            <el-table-column label="风险等级" align="center" prop="riskLevel">
              <template slot-scope="scope">
                <dict-tag
                  :options="dict.type.list_risk_level"
                  :value="scope.row.riskLevel"
                />
              </template>
            </el-table-column>
            <el-table-column
              label="管控措施"
              align="center"
              prop="controlMeasure"
            />
            <el-table-column label="隐患等级" align="center" prop="dangerLevel">
              <template slot-scope="scope">
                <dict-tag
                  :options="dict.type.list_danger_level"
                  :value="scope.row.dangerLevel"
                />
              </template>
            </el-table-column>
            <el-table-column
              label="规范依据"
              align="center"
              prop="normativeBasis"
            />
          </el-table>
          <pagination
            v-show="deviseListTotal > 0"
            :total="deviseListTotal"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getTotleDate"
          />
        </el-col>
      </el-row>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="updatePlanHand">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listPlan,
  getPlan,
  delPlan,
  addPlan,
  updatePlan,
  getTree,
  updatePlanBatch,
  getPlanSelect,
  getPlanSelectCancel,
  getPlanSelectCancelOver,
} from "@/api/biz/exclude/plan";
import { mapState } from "vuex";
import { listUser } from "@/api/common/user";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import { treeselect } from "@/api/list/type";
import { listDevise } from "@/api/list/devise";
import { listConstruction } from "@/api/list/construction";
import { listMaintenance } from "@/api/list/maintenance";
import { listManage } from "@/api/list/manage";
export default {
  name: "Plan",
  components: {
    Treeselect,
  },
  dicts: [
    "biz_date_type",
    "biz_exclude_type",
    "list_danger_level",
    "list_risk_level",
  ], //周期类型  dateType 排查类型 隐患等级  风险等级
  data() {
    return {
      sortValueBy: "ORDER_SELECTED",
      openUpdateLook:false,
      idsdisabledOver: true,
      SelectData: null,
      plainA: false,
      plainB: true,
      plainC: true,
      plainD: true,
      //排查责任人
      correctorUserIdData: null,
      //排查范围下拉树
      getTreeData: null,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      idsdisabled: true,
      disabledId: true,
      // 子表选中数据
      checkedBizExcludeUser: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 隐患风险排查计划表格数据
      planList: [],
      // 隐患风险排查计划人员主子表格数据
      bizExcludeUserList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      openUpdate: false,
      openBatch: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectId: this.$store.state.app.selectData,
        userIds: null,
        isTask: null,
        delFlag: null,
        listType: "1",
      },
      // 表单参数
      form: {
        excludeType: [],
        excludeFrequency: null,
        dateType: null,
        dateRange: null,
        regionIds: null,
        userIds: null,
        userIds: null,
        userIds: null,
      },
      // 表单校验
      rules: {
        listType: [
          { required: true, message: "清单类型不能为空", trigger: "change" },
        ],
        listId: [
          { required: true, message: "清单id不能为空", trigger: "blur" },
        ],
        excludeType: [
          { required: true, message: "排查类别不能为空", trigger: "change" },
        ],
        excludeFrequency: [
          { required: true, message: "排查频次不能为空", trigger: "blur" },
        ],
        dateType: [
          { required: true, message: "频次类不能为空", trigger: "change" },
        ],
      },
      deptName: undefined,
      // 部门树选项
      deptOptions: undefined,
      typeNoData: {
        typeNo: 1,
      },
      defaultProps: {
        children: "children",
        label: "label",
      },
      // 设计清单表格数据
      deviseList: [],
      deviseListTotal: 0,
      valueBatch: "",
      valueBatchData: "",
      valueBatchDataOver: "",
      optionsBatch: [
        {
          value: "1",
          label: "排查类别及频次",
        },
        {
          value: "2",
          label: "排查时间",
        },
        {
          value: "3",
          label: "排查范围",
        },
        {
          value: "4",
          label: "排查责任人",
        },
        {
          value: "5",
          label: "全部字段",
        },
      ],
      optionsBatchData: [
        {
          value: "1",
          label: "生成代办任务",
        },
        {
          value: "2",
          label: "取消代办任务",
        },
      ],
      optionsBatchDataOver: [
        {
          value: "1",
          label: "全部生成代办任务",
        },
        {
          value: "2",
          label: "全部取消代办任务",
        },
      ],
    };
  },
  created() {
    this.getList();
    this.getDeptTree();
  },
  computed: {
    ...mapState(["app"]),
  },
  watch: {
    app: {
      handler(newVal, oldVal) {
        this.disabledId = false;
        this.idsdisabledOver = false;
        this.queryParams.projectId = newVal.selectData;
        if (this.queryParams.projectId != null) {
          this.disabledId = false;
        }
        this.getList();
      },
      deep: true,
    },
    // 根据名称筛选部门树
    deptName(val) {
      this.$refs.tree.filter(val);
    },
    ids: {
      handler(newVal, oldVal) {
        if (newVal.length == 0) {
          this.idsdisabled = true;
        } else {
          this.idsdisabled = false;
        }
      },
      deep: true,
    },
  },
  methods: {
    /** 查询隐患风险排查计划列表 */
    getList() {
      this.loading = true;
      listPlan(this.queryParams).then((response) => {
        this.planList = response.rows;
        for (let i = 0; i < this.planList.length; i++) {
          if (this.planList[i].excludeType != null) {
            this.planList[i].excludeType =
              this.planList[i].excludeType.split(",");
          }
        }
        this.total = response.total;
        this.loading = false;
      });
      listUser(this.queryParams).then((response) => {
        this.correctorUserIdData = response.rows;
        this.deviseListTotal = response.total;
      });
      getTree(this.queryParams).then((response) => {
        this.getTreeData = response.data;
        // this.deviseListTotal = response.total;
      });
      listDevise(this.queryParams).then((response) => {
        this.deviseList = response.rows;
        this.deviseListTotal = response.total;
      });
      getPlanSelect().then((response) => {
        this.SelectData = response.data;
        this.deviseListTotal = response.total;
      });
    },
    normalizer(node) {
      return {
        ...node,
        // id: node.key,
        label: node.name,
        // children: node.subOptions,
      };
    },
    /** 查询部门下拉树结构 */
    getDeptTree() {
      treeselect(this.typeNoData).then((response) => {
        this.deptOptions = response.data;
      });
    },
    // 筛选节点
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
    // 节点单击事件
    handleNodeClick(data) {
      this.queryParams.typeNo = data.id;
      // this.getList();
      if (this.typeNoData.typeNo == 1) {
        listDevise(this.queryParams).then((response) => {
          this.deviseList = response.rows;
        });
      } else if (this.typeNoData.typeNo == 2) {
        listConstruction(this.queryParams).then((response) => {
          this.deviseList = response.rows;
        });
      } else if (this.typeNoData.typeNo == 3) {
        listMaintenance(this.queryParams).then((response) => {
          this.deviseList = response.rows;
        });
      } else {
        listManage(this.queryParams).then((response) => {
          this.deviseList = response.rows;
        });
      }
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        listType: null,
        listId: null,
        excludeType: [],
        excludeFrequency: null,
        userIds: null,
        dateType: null,
        startDate: null,
        endDate: null,
        regionIds: null,
        isTask: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
      };
      this.bizExcludeUserList = [];
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
      this.valueBatch = null;
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      if (this.queryParams.projectId == null) {
        this.$message({
          message: "请选择项目部后再点击!",
          type: "warning",
        });
      } else {
        this.open = true;
        this.title = "添加隐患风险排查计划";
        this.queryParams.pageNum = 1;
        this.queryParams.pageSize = 10;
        this.getDeptTree();
      }
    },
    // 查看
    handleUpdateLook(row){
      this.reset();
      const id = row.id || this.ids;
      getPlan(id).then((response) => {
        this.form = response.data;
        if (this.form.excludeType != null) {
          this.form.excludeType = this.form.excludeType.split(",");
        } else {
          this.form.excludeType = [];
        }
        this.bizExcludeUserList = response.data.bizExcludeUserList;
        this.openUpdateLook = true;
        this.title = "查看隐患风险排查计划";
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getPlan(id).then((response) => {
        this.form = response.data;
        if (this.form.excludeType != null) {
          this.form.excludeType = this.form.excludeType.split(",");
        } else {
          this.form.excludeType = [];
        }
        this.bizExcludeUserList = response.data.bizExcludeUserList;
        this.openUpdate = true;
        this.title = "修改隐患风险排查计划";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs.formData.validate((valid) => {
        if (valid) {
          console.log(this.form.excludeType);
          this.form.excludeType = this.form.excludeType.join(",");
          this.form.bizExcludeUserList = this.bizExcludeUserList;
          if (this.form.id != null) {
            updatePlan(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.openUpdate = false;
              this.getList();
            });
          } else {
            addPlan(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除隐患风险排查计划编号为"' + ids + '"的数据项？')
        .then(function () {
          return delPlan(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 隐患风险排查计划人员主子序号 */
    rowBizExcludeUserIndex({ row, rowIndex }) {
      row.index = rowIndex + 1;
    },
    /** 隐患风险排查计划人员主子添加按钮操作 */
    handleAddBizExcludeUser() {
      let obj = {};
      obj.userId = "";
      this.bizExcludeUserList.push(obj);
    },
    /** 隐患风险排查计划人员主子删除按钮操作 */
    handleDeleteBizExcludeUser() {
      if (this.checkedBizExcludeUser.length == 0) {
        this.$modal.msgError("请先选择要删除的隐患风险排查计划人员主子数据");
      } else {
        const bizExcludeUserList = this.bizExcludeUserList;
        const checkedBizExcludeUser = this.checkedBizExcludeUser;
        this.bizExcludeUserList = bizExcludeUserList.filter(function (item) {
          return checkedBizExcludeUser.indexOf(item.index) == -1;
        });
      }
    },
    /** 复选框选中数据 */
    handleBizExcludeUserSelectionChange(selection) {
      this.checkedBizExcludeUser = selection.map((item) => item.index);
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "exclude/plan/export",
        {
          ...this.queryParams,
        },
        `plan_${new Date().getTime()}.xlsx`
      );
    },
    plainDataA() {
      this.queryParams.listType = "1";
      this.plainA = false;
      this.plainB = true;
      this.plainC = true;
      this.plainD = true;
      this.typeNoData.typeNo = 1;
      listDevise(this.queryParams).then((response) => {
        this.deviseList = response.rows;
        this.getList();
      });
    },
    plainDataB() {
      this.queryParams.listType = "2";
      this.plainA = true;
      this.plainB = false;
      this.plainC = true;
      this.plainD = true;
      this.typeNoData.typeNo = 2;
      listConstruction(this.queryParams).then((response) => {
        this.deviseList = response.rows;
      });
      this.loading = true;
      listPlan(this.queryParams).then((response) => {
        this.planList = response.rows;
        for (let i = 0; i < this.planList.length; i++) {
          if (this.planList[i].excludeType != null) {
            this.planList[i].excludeType =
              this.planList[i].excludeType.split(",");
          }
        }
        this.total = response.total;
        this.loading = false;
      });
    },
    plainDataC() {
      this.queryParams.listType = "3";
      this.plainA = true;
      this.plainB = true;
      this.plainC = false;
      this.plainD = true;
      this.typeNoData.typeNo = 3;
      listMaintenance(this.queryParams).then((response) => {
        this.deviseList = response.rows;
      });
      this.loading = true;
      listPlan(this.queryParams).then((response) => {
        this.planList = response.rows;
        for (let i = 0; i < this.planList.length; i++) {
          if (this.planList[i].excludeType != null) {
            this.planList[i].excludeType =
              this.planList[i].excludeType.split(",");
          }
        }
        this.total = response.total;
        this.loading = false;
      });
    },
    plainDataD() {
      this.queryParams.listType = "4";
      this.plainA = true;
      this.plainB = true;
      this.plainC = true;
      this.plainD = false;
      this.typeNoData.typeNo = 4;
      listManage(this.queryParams).then((response) => {
        this.deviseList = response.rows;
      });
      this.loading = true;
      listPlan(this.queryParams).then((response) => {
        this.planList = response.rows;
        for (let i = 0; i < this.planList.length; i++) {
          if (this.planList[i].excludeType != null) {
            this.planList[i].excludeType =
              this.planList[i].excludeType.split(",");
          }
        }
        this.total = response.total;
        this.loading = false;
      });
    },
    openBatchOpen() {
      this.reset();
      this.openBatch = true;
    },
    // 批量修改
    batchSubmitForm() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          // 排查类别及频次
          let data = {};
          // excludeFrequency
          if (this.form.excludeFrequency != null) {
            this.form.excludeFrequency = this.form.excludeFrequency + "";
          }
          this.form.excludeType = this.form.excludeType.join(",");
          this.form = Object.fromEntries(
            Object.entries(this.form).filter(
              ([key, value]) =>
                value !== null &&
                value !== undefined &&
                Object.keys(value).length !== 0
            )
          );
          data = {
            ids: this.ids,
            ...this.form,
          };
          updatePlanBatch(data).then((response) => {
            this.$modal.msgSuccess("修改成功");
            this.openBatch = false;
            this.valueBatch = null;
            this.getList();
          });
        }
      });
    },
    updatePlanHand() {
      let data = {
        listIds: this.ids,
        listType: this.queryParams.listType,
        projectId: this.queryParams.projectId,
      };
      addPlan(data).then((response) => {
        this.$modal.msgSuccess("新增成功");
        this.open = false;
        this.getList();
      });
    },
    handleClose() {
      this.openBatch = false;
      this.valueBatch = null;
    },
    openBatchOpenDate() {
      let data = {
        ids: this.ids,
        listType: this.queryParams.listType,
        projectId: this.queryParams.projectId,
      };
      if (this.valueBatchData == 1) {
        getPlanSelectCancelOver(data).then((response) => {
          this.valueBatchData = null;
          this.$message({
            message: "生成代办任务成功",
            type: "success",
          });
        });
      } else if (this.valueBatchData == 2) {
        getPlanSelectCancel(data).then((response) => {
          this.valueBatchData = null;
          this.$message({
            message: "取消代办任务成功",
            type: "success",
          });
        });
      }
    },
    openBatchOpenDateOver() {
      let data = {
        listType: this.queryParams.listType,
        projectId: this.queryParams.projectId,
      };
      if (this.valueBatchDataOver == 1) {
        getPlanSelectCancelOver(data).then((response) => {
          console.log(data);
          this.valueBatchDataOver = null;
          this.$message({
            message: "全部生成代办任务成功",
            type: "success",
          });
        });
      } else {
        getPlanSelectCancel(data).then((response) => {
          this.valueBatchDataOver = null;
          this.$message({
            message: "全部取消代办任务成功",
            type: "success",
          });
        });
      }
      // getPlanSelectCancelOver(data).then((response) => {
      //   this.valueBatchDataOver = null;

      // })
    },
    getTotleDate() {
      if (this.typeNoData.typeNo == 1) {
        listDevise(this.queryParams).then((response) => {
          this.deviseList = response.rows;
          this.deviseListTotal = response.total;
        });
      } else if (this.typeNoData.typeNo == 2) {
        listConstruction(this.queryParams).then((response) => {
          this.deviseList = response.rows;
          this.deviseListTotal = response.total;
        });
      } else if (this.typeNoData.typeNo == 3) {
        listMaintenance(this.queryParams).then((response) => {
          this.deviseList = response.rows;
          this.deviseListTotal = response.total;
        });
      } else {
        listManage(this.queryParams).then((response) => {
          this.deviseList = response.rows;
          this.deviseListTotal = response.total;
        });
      }
    },

    checkboxChange() {
      console.log(this.form.excludeType);
    },
  },
};
</script>
<style scoped>
.tagname {
  display: inline-block;
}
/* /deep/ .el-input.is-focus .el-input__inner {
  caret-color: rgb(224, 78, 243);
  border: 1px solid rgb(224, 78, 243) !important;
  transition: all 0.3s;
} */
.custom-select /deep/ .el-input__inner {
  color: #fff !important;
  /* border: 1px solid #326AFF; */
  background: rgb(31, 99, 255, 0.8) !important;
}
</style>
>
